import { craeteEffect, effectTypes } from './helper'

/**
 * 监听action触发 返回一个完整的action对象
 * @export
 * @param {*} actionType
 */
export function take(actionType) {
    return craeteEffect(effectTypes.TAKE, { actionType })
}

/**
 * 处理 take effect 
 * @export
 * @param {*} env
 * @param {*} effect
 * @param {*} next
 */
export function runTakeEffect(env, effect, next) {
    const { store, chanel } = env
    const { payload: { actionType } } = effect

    // 等待对应action触发
    // 添加订阅 
    chanel.take(actionType, (action) => {
        next(action)
    })
}